﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections;
using QLNhaThuoc.DTO;

namespace QLNhaThuoc.DAL
{
    class LoaiNhanVienDA:DataProvider
    {
        public LoaiNhanVienDA()
        {
            connect();
            fillMyTable("LOAI_NHAN_VIEN");
        }

        public void insert(LoaiNhanVien info)
        {
            DataRow row = myTable.NewRow();
            row["MaLoai"] = info.MaLoai;
            row["TenLoai"] = info.TenLoai;
            myTable.Rows.Add(row);

            updateMyTable();
        }

        public void delete(LoaiNhanVien info)
        {
            myTable.Rows.Find(info.MaLoai).Delete();

            updateMyTable();
        }

        public void update(LoaiNhanVien info)
        {
            DataRow row = myTable.Rows.Find(info.MaLoai);
            row["MaLoai"] = info.MaLoai;
            row["TenLoai"] = info.TenLoai;

            updateMyTable();
        }

        public bool KiemTraPK(LoaiNhanVien info)
        {
            DataRow row = myTable.Rows.Find(info.MaLoai);
            if (row != null)
                return false;
            return true;
        }

        public LoaiNhanVien[] LayListLoaiNV()
        {
            ArrayList list = DongHopDuLieuTuDataTable();
            int n = list.Count;
            LoaiNhanVien[] kq = new LoaiNhanVien[n];

            for (int i = 0; i < n; i++)
            {
                kq[i] = (LoaiNhanVien)list[i];
            }

            return kq;
        }

        public override object ConvertOneRowIntoDTO(DataTable table, int i)
        {
            LoaiNhanVien obj = new LoaiNhanVien();
            obj.MaLoai = table.Rows[i]["MaLoai"].ToString();
            obj.TenLoai = table.Rows[i]["TenLoai"].ToString();

            return obj;
        }
    }
}
